<?php

namespace App\Http\Controllers;

use App\Http\Helpers\Sign;
use App\Providers\AppServiceProvider;
use Illuminate\Http\Request;
use App\Http\Services\AppService;

class AppController extends Controller
{
    /**
     *应用的统一入口
     * @author: lican<364548233@qq.com>
     */
    public function index(Request $request){
        $type = $request->input('type');

        switch($type){
            case "open":
                return$this->open($request);
            case "close":
                return $this->close($request);
            case "trigger":
                return $this->trigger($request);
            case "manage":
                return $this->manage($request);
            case "monitor":
                return $this->monitor($request);
            default:
                return $this->open($request);
        }
    }

    /**
     *应用开启
     * @author: lican<364548233@qq.com>
     */
    public function open($request){
        $data = file_get_contents("php://input");
        Sign::writeLog("开启应用：", $data, 'open');
        $schoolCode = $request->input('school_code');
        $host = $request->input('gate_host');
        //开启应用实操
        $result = AppService::open($schoolCode, $host);

        return $result;
    }

    /**
     *关闭应用
     * @author: lican<364548233@qq.com>
     */
    public function close($request){
        $data = file_get_contents("php://input");
        Sign::writeLog("关闭应用：", $data, 'open');
        $schoolCode = $request->input('school_code');
        $result = AppService::close($schoolCode);
        return $result;
    }

}
